package io.renren.modules.pro.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.pro.entity.ItemEntity;
import io.renren.modules.pro.service.ItemService;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 * 
 * @author zhangyue
 * @email zhangyue086@163.com
 * @date 2022-04-25 15:48:59
 */
@RestController
@RequestMapping("/pro/item")
public class ItemController extends AbstractController {
	@Autowired
	private ItemService itemService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("item:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
		PageUtils page = itemService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("item:info")
	public R info(@PathVariable("id") Long id){
		ItemEntity item = itemService.getById(id);
		
		return R.ok().put("item", item);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("item:save")
	public R save(@RequestBody ItemEntity item){
		itemService.save(item);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("item:update")
	public R update(@RequestBody ItemEntity item){
		itemService.updateById(item);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("item:delete")
	public R delete(@RequestBody Long[] ids){
		itemService.removeByIds(Arrays.asList(ids));
		return R.ok();
	}
	
}
